package com.ysd.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ysd.dao.impl.ProductDaoImpl;
import com.ysd.dao.impl.ProductDetailsDaoImpl;
import com.ysd.dao.impl.ProductcategoryDaoImpl;
import com.ysd.entity.Product;
import com.ysd.entity.Productcategory;

public class ProductDetailServlet extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 调用实现类
		// 产品分类
		ProductcategoryDaoImpl pyDao = new ProductcategoryDaoImpl();
		List<Productcategory> pyList = pyDao.getProductcategory();
		request.setAttribute("pyList", pyList);
		
		//利用id查商品的信息
		//接收前台传来的信息
		int cId = Integer.parseInt(request.getParameter("productId"));
		ProductDetailsDaoImpl pdDao = new ProductDetailsDaoImpl();
		List<Product> ProductDetailsList = pdDao.getroductDetails(cId);
		request.setAttribute("pdList", ProductDetailsList);
		
		request.getRequestDispatcher("productdetails.jsp").forward(request, response);// 转发
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
